package com.goodving.guli.bt.ui;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;

import com.goodving.guli.R;
import com.goodving.guli.view.C4005t;
import com.goodving.guli.view.PageIndicator;

/**
 * Created by john on 2015/12/2.
 */
public class CirclePageIndicator extends View implements PageIndicator {
    private static final int f10372a = -1;
    private float f10373b;
    private final Paint f10374c;
    private final Paint f10375d;
    private final Paint f10376e;
    private ViewPager f10377f;
    private ViewPager.OnPageChangeListener f10378g; // bz
    private int f10379h;
    private int f10380i;
    private float f10381j;
    private int f10382k;
    private int f10383l;
    private boolean f10384m;
    private boolean f10385n;
    private float f10386o;
//    private int f10387p;
    private float f10388q;
    private int f10389r;
    private boolean f10390s;



    static class SavedState extends BaseSavedState {
        public static final Creator<SavedState> CREATOR;
        int f10371a;



        static {
            CREATOR = new C1860b();
        }

        public SavedState(Parcel parcel) {
            super(parcel);
            this.f10371a = parcel.readInt();
        }

        public SavedState(Parcelable parcelable) {
            super(parcelable);
        }

        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeInt(this.f10371a);
        }
    }

    public CirclePageIndicator(Context context) {
        this(context, null);
    }

    public CirclePageIndicator(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, R.attr.vpiCirclePageIndicatorStyle);
    }

    public CirclePageIndicator(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.f10374c = new Paint(1);
        this.f10375d = new Paint(1);
        this.f10376e = new Paint(1);
        this.f10388q = -1;
        this.f10389r = f10372a;
        if (!isInEditMode()) {
            Resources resources = getResources();
            int color = resources.getColor(R.color.default_circle_indicator_page_color);
            int color2 = resources.getColor(R.color.default_circle_indicator_fill_color);
            int integer = resources.getInteger(R.integer.default_circle_indicator_orientation);
            int color3 = resources.getColor(R.color.default_circle_indicator_stroke_color);
            float dimension = resources.getDimension(R.dimen.default_circle_indicator_stroke_width);
            float dimension2 = resources.getDimension(R.dimen.default_circle_indicator_radius);
            boolean z = resources.getBoolean(R.bool.default_circle_indicator_centered);
            boolean z2 = resources.getBoolean(R.bool.default_circle_indicator_snap);
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C4005t.CirclePageIndicator, i, 0);
            this.f10384m = obtainStyledAttributes.getBoolean(2, z);
            this.f10383l = obtainStyledAttributes.getInt(0, integer);
            this.f10374c.setStyle(Paint.Style.FILL);
            this.f10374c.setColor(obtainStyledAttributes.getColor(5, color));
            this.f10375d.setStyle(Paint.Style.STROKE);
            this.f10375d.setColor(obtainStyledAttributes.getColor(8, color3));
            this.f10375d.setStrokeWidth(obtainStyledAttributes.getDimension(3, dimension));
            this.f10376e.setStyle(Paint.Style.FILL);
            this.f10376e.setColor(obtainStyledAttributes.getColor(4, color2));
            this.f10373b = obtainStyledAttributes.getDimension(6, dimension2);
            this.f10385n = obtainStyledAttributes.getBoolean(7, z2);
            this.f10386o = obtainStyledAttributes.getDimension(9, 12.0f);
            Drawable drawable = obtainStyledAttributes.getDrawable(1);
            if (drawable != null) {
                setBackgroundDrawable(drawable);
            }
            obtainStyledAttributes.recycle();
//            this.f10387p = aZ.m3575a(ViewConfiguration.get(context));
        }
    }

    private int m14950h(int i) {
        int mode = MeasureSpec.getMode(i);
        int size = MeasureSpec.getSize(i);
        if (mode == 1073741824 || this.f10377f == null) {
            return size;
        }
        int k = getCount();
        k = (int) (((((float) (k + f10372a)) * this.f10386o) + (((float) (getPaddingLeft() + getPaddingRight())) + (((float) (k * 2)) * this.f10373b))) + 1.0f);
        return mode == Integer.MIN_VALUE ? Math.min(k, size) : k;
    }

    private int m14951i(int i) {
        int mode = MeasureSpec.getMode(i);
        int size = MeasureSpec.getSize(i);
        if (mode == 1073741824) {
            return size;
        }
        int paddingTop = (int) ((((2.0f * this.f10373b) + ((float) getPaddingTop())) + ((float) getPaddingBottom())) + 1.0f);
        return mode == Integer.MIN_VALUE ? Math.min(paddingTop, size) : paddingTop;
    }

    public void setStrokeWidth (float f) { // m14952a
        this.f10375d.setStrokeWidth(f);
        invalidate();
    }

    public void onPageSelected (int i) { // m14953a
        if (this.f10385n || this.f10382k == 0) {
            this.f10379h = i - getOffset();
            this.f10380i = i - getOffset();
            invalidate();
        }
        if (this.f10378g != null) {
            this.f10378g.onPageSelected(i);
        }
    }

    public void onPageScrolled(int i, float f, int i2) {
        this.f10379h = i - getOffset();
        this.f10381j = f;
        invalidate();
        if (this.f10378g != null) {
            this.f10378g.onPageScrolled(i, f, i2);
        }
    }

    public void setViewPager(ViewPager viewPager) {  //setViewPager
        if (this.f10377f != viewPager) {
            if (this.f10377f != null) {
                this.f10377f.setOnPageChangeListener(null);
            }
            if (viewPager.getAdapter() == null) {
                throw new IllegalStateException("ViewPager does not have adapter instance.");
            }
            this.f10377f = viewPager;
            this.f10377f.setOnPageChangeListener((ViewPager.OnPageChangeListener) this);
            invalidate();
        }
    }

    public void setViewPager(ViewPager viewPager, int i) {
        setViewPager(viewPager);
        setCurrentItem(i);//m14973g(i);
    }

    public void setOnPageChangeListener (ViewPager.OnPageChangeListener bzVar) { // m14957a
        this.f10378g = bzVar;
    }

    public void setCentered(boolean z) {
        this.f10384m = z;
        invalidate();
    }

    public boolean isCentered() {
        return this.f10384m;
    }

    public int getPageColor () { //m14960b
        return this.f10374c.getColor();
    }

    public void setRadius(float f) {
        this.f10373b = f;
        invalidate();
    }

    public void onPageScrollStateChanged (int i) { // m14962b
        this.f10382k = i;
        if (this.f10378g != null) {
            this.f10378g.onPageScrollStateChanged(i);//m3591b(i);
        }
    }

    public void setSnap(boolean z) {
        this.f10385n = z;
        invalidate();
    }

    public int getStrokeColor() { // m14964c
        return this.f10376e.getColor();
    }

    public void setPageColor(int i) {
        this.f10374c.setColor(i);
        invalidate();
    }

    public int getOrientation() {
        return this.f10383l;
    }

    public void setFillColor(int i) {
        this.f10376e.setColor(i);
        invalidate();
    }

    public int getFillColor() { //m14968e
        return this.f10375d.getColor();
    }

    public void setOrientation(int i) {
        switch (i) {
            case 0 /*0*/:
            case 1 /*1*/:
                this.f10383l = i;
                requestLayout();
            default:
                throw new IllegalArgumentException("Orientation must be either HORIZONTAL or VERTICAL.");
        }
    }

    public float getStrokeWidth() {
        return this.f10375d.getStrokeWidth();
    }

    public void setStrokeColor(int i) {
        this.f10375d.setColor(i);
        invalidate();
    }

    public float getRadius() {
        return this.f10373b;
    }

    public void setCurrentItem(int i) {
        if (this.f10377f == null) {
            throw new IllegalStateException("ViewPager has not been bound.");
        }
        this.f10377f.setCurrentItem(getOffset() + i);
        this.f10379h = i;
        invalidate();
    }

    public boolean isSnap() {
        return this.f10385n;
    }

    public void notifyDataSetChanged() {
        invalidate();
    }

    public ViewPager getViewPager() {
        return this.f10377f;
    }

    public int getCount() { // m14977k
        //return this.f10377f == null ? 0 : this.f10377f.m2476b().m193b();
        return this.f10377f == null ? 0 : this.f10377f.getAdapter().getCount();
    }

    public int getOffset() {
        return 0;
    }

    protected void onDraw(Canvas canvas) {
        int i = 0;
        super.onDraw(canvas);
        if (this.f10377f != null) {
            int k = getCount();
            if (k != 0) {
                if (this.f10379h < 0) {
                    setCurrentItem(0);
                }
                if (this.f10379h >= k) {
                    setCurrentItem(k + f10372a);
                    return;
                }
                int width;
                int paddingLeft;
                int paddingRight;
                int paddingTop;
                if (this.f10383l == 0) {
                    width = getWidth();
                    paddingLeft = getPaddingLeft();
                    paddingRight = getPaddingRight();
                    paddingTop = getPaddingTop();
                } else {
                    width = getHeight();
                    paddingLeft = getPaddingTop();
                    paddingRight = getPaddingBottom();
                    paddingTop = getPaddingLeft();
                }
                float f = this.f10373b + ((float) paddingTop);
                float f2 = ((float) paddingLeft) + this.f10373b;
                if (this.f10384m) {
                    f2 += ((float) (((width - paddingLeft) - paddingRight) - ((int) (((((float) (k * 2)) * this.f10373b) + (((float) (k + f10372a)) * this.f10386o)) + 1.0f)))) / 2.0f;
                }
                float f3 = this.f10373b;
                if (this.f10375d.getStrokeWidth() > 0.0f) {
                    f3 -= this.f10375d.getStrokeWidth() / 2.0f;
                }
                while (i < k) {
                    float f4;
                    float f5 = (((float) i) * (this.f10386o + (this.f10373b * 2.0f))) + f2;
                    if (this.f10383l == 0) {
                        f4 = f5;
                        f5 = f;
                    } else {
                        f4 = f;
                    }
                    if (this.f10374c.getAlpha() > 0) {
                        canvas.drawCircle(f4, f5, f3, this.f10374c);
                    }
                    if (f3 != this.f10373b) {
                        canvas.drawCircle(f4, f5, this.f10373b, this.f10375d);
                    }
                    i++;
                }
                f3 = ((float) (this.f10385n ? this.f10380i : this.f10379h)) * (this.f10386o + (this.f10373b * 2.0f));
                if (!this.f10385n) {
                    f3 += this.f10381j * (this.f10386o + (this.f10373b * 2.0f));
                }
                if (this.f10383l == 0) {
                    f2 += f3;
                } else {
                    float f6 = f2 + f3;
                    f2 = f;
                    f = f6;
                }
                canvas.drawCircle(f2, f, this.f10373b, this.f10376e);
            }
        }
    }

    protected void onMeasure(int i, int i2) {
        if (this.f10383l == 0) {
            setMeasuredDimension(m14950h(i), m14951i(i2));
        } else {
            setMeasuredDimension(m14951i(i), m14950h(i2));
        }
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        SavedState savedState = (SavedState) parcelable;
        super.onRestoreInstanceState(savedState.getSuperState());
        this.f10379h = savedState.f10371a;
        this.f10380i = savedState.f10371a;
        requestLayout();
    }

    public Parcelable onSaveInstanceState() {
        CirclePageIndicator.SavedState savedState = new SavedState(super.onSaveInstanceState());
        savedState.f10371a = this.f10379h;
        return savedState;
    }
}
